import sys
sys.path.append("C:\\Panda3D-1.7.2\\")
from direct.showbase.DirectObject import DirectObject
from direct.task import Task
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import *
from math import pi

class Cannon(DirectObject):
    def __init__(self):
        self.node = NodePath('physicsNode')
        self.node.reparentTo(render)
        self.cannonNode = ActorNode('cannon')
        self.cannonNodePath = self.node.attachNewNode(self.cannonNode)       
        
        #self.cannon.reparentTo(self.cannonNodePath)

        self.cannonHead = self.loadObject(loader.loadTexture("../media/cannonhead.png"))
        self.cannonHead.setPos(-2.80,10,-1.85)
        
        self.cannonHead.setR(30)
        
        self.cannon = self.loadObject(loader.loadTexture("../media/cannon.png"))
        self.cannon.setPos(-3.1,10,-2.1)

        
        #self.cannonHead.reparentTo(self.cannonNodePath)

        self.cannonNodePath.setScale(1)
        self.cannonNodePath.setPos(-3,10,-2)
        self.R = self.cannonNodePath.getR()

    def loadObject(self, textureobj):
        obj = loader.loadModel("../media/plane")
        obj.reparentTo(render)
        obj.setBin("unsorted", 0)
        obj.setDepthTest(False)

        obj.setTransparency(1)
        obj.setTexture(textureobj, 1)
        return obj

    def moveCannon(self, direction):
        if direction == 1 and self.cannonNodePath.getR() < 0:
            self.cannonHead.setR(self.cannonHead.getR() + 5)
            self.cannonNodePath.setR(self.cannonNodePath.getR() + 5)
            self.R = self.cannonNodePath.getR()
        elif direction == 0 and self.cannonNodePath.getR() > -60:
            self.cannonHead.setR(self.cannonHead.getR() - 5)
            self.cannonNodePath.setR(self.cannonNodePath.getR() - 5)
            self.R = self.cannonNodePath.getR()
 
